package com.laixu.estore.web.controller;

import com.laixu.estore.bean.dto.OrderCreateDTO;
import com.laixu.estore.bean.vo.OrderInfoVO;
import com.laixu.estore.service.OrderService;
import com.laixu.estore.web.response.Result;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Auther: vanse(lc)
 * @Date: 2025/4/14-04-14-16:55
 * @Description：com.briup.estore.web.controller
 */
@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrderController {
    private final OrderService orderService;
    @PostMapping
    @ApiOperation("创建订单")
    public Result createOrder(@RequestBody OrderCreateDTO orderCreateDTO, HttpServletRequest request) {
        String userId = (String) request.getAttribute("userId");
        orderService.createOrder(orderCreateDTO, Integer.parseInt(userId));

        return Result.success();
    }

    @GetMapping("/")
    public Result orderList(HttpServletRequest request){
        String userIdStr = (String) request.getAttribute("userId");
        int userId = Integer.parseInt(userIdStr);
        List<OrderInfoVO> list =  orderService.orderList(userId);
        return Result.success(list);
    }
}